#!/bin/bash

# Webhook 配置
SECRET="b63929404f905971d61d7"
WEBHOOK_URL="https://www.duzhaosongyue.com"

# 正确的 JSON 请求体
JSON_BODY='{"ref":"refs/heads/main","repository":{"name":"brief-pro","ssh_url":"git@jihulab.com:duzhaosongyue-springboot/brief-pro.git"}}'

# 计算 HMAC SHA1 签名
echo "计算 Webhook 签名..."
SIGNATURE=$(echo -n "$JSON_BODY" | openssl dgst -sha1 -hmac "$SECRET" | awk '{print "sha1="$2}')

echo "计算出的签名: $SIGNATURE"
echo ""

# 发送 Webhook 请求
echo "发送 Webhook 请求到 $WEBHOOK_URL..."
echo "请求体: $JSON_BODY"
echo ""

# 使用 curl 发送请求
curl -v -X POST \
  -H "Content-Type: application/json" \
  -H "X-GitHub-Event: Push Hook" \
  -H "X-Hub-Signature: $SIGNATURE" \
  -d "$JSON_BODY" \
  "$WEBHOOK_URL"

echo ""
echo "请求已完成"